/**
 * Copyright &copy; 2012-2016 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.thinkgem.jeesite.modules.hk.sys.web.job;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.thinkgem.jeesite.common.config.Global;
import com.thinkgem.jeesite.common.persistence.Page;
import com.thinkgem.jeesite.common.web.BaseController;
import com.thinkgem.jeesite.common.utils.StringUtils;
import com.thinkgem.jeesite.modules.hk.sys.entity.job.HkUserRecruitHotsearch;
import com.thinkgem.jeesite.modules.hk.sys.service.job.HkUserRecruitHotsearchService;

/**
 * 职位热搜Controller
 * @author 罗天文
 * @version 2018-06-15
 */
@Controller
@RequestMapping(value = "${adminPath}/sys/job/hkUserRecruitHotsearch")
public class HkUserRecruitHotsearchController extends BaseController {

	@Autowired
	private HkUserRecruitHotsearchService hkUserRecruitHotsearchService;
	
	@ModelAttribute
	public HkUserRecruitHotsearch get(@RequestParam(required=false) String id) {
		HkUserRecruitHotsearch entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = hkUserRecruitHotsearchService.get(id);
		}
		if (entity == null){
			entity = new HkUserRecruitHotsearch();
		}
		return entity;
	}
	
	@RequiresPermissions("sys:job:hkUserRecruitHotsearch:view")
	@RequestMapping(value = {"list", ""})
	public String list(HkUserRecruitHotsearch hkUserRecruitHotsearch, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<HkUserRecruitHotsearch> page = hkUserRecruitHotsearchService.findPage(new Page<HkUserRecruitHotsearch>(request, response), hkUserRecruitHotsearch); 
		model.addAttribute("page", page);
		return "hk/sys/job/hkUserRecruitHotsearchList";
	}

	@RequiresPermissions("sys:job:hkUserRecruitHotsearch:view")
	@RequestMapping(value = "form")
	public String form(HkUserRecruitHotsearch hkUserRecruitHotsearch, Model model) {
		model.addAttribute("hkUserRecruitHotsearch", hkUserRecruitHotsearch);
		return "hk/sys/job/hkUserRecruitHotsearchForm";
	}

	@RequiresPermissions("sys:job:hkUserRecruitHotsearch:edit")
	@RequestMapping(value = "save")
	public String save(HkUserRecruitHotsearch hkUserRecruitHotsearch, Model model, RedirectAttributes redirectAttributes) {
		if (!beanValidator(model, hkUserRecruitHotsearch)){
			return form(hkUserRecruitHotsearch, model);
		}
		hkUserRecruitHotsearchService.save(hkUserRecruitHotsearch);
		addMessage(redirectAttributes, "保存职位热搜成功");
		return "redirect:"+Global.getAdminPath()+"/sys/job/hkUserRecruitHotsearch/?repage";
	}
	
	@RequiresPermissions("sys:job:hkUserRecruitHotsearch:edit")
	@RequestMapping(value = "delete")
	public String delete(HkUserRecruitHotsearch hkUserRecruitHotsearch, RedirectAttributes redirectAttributes) {
		hkUserRecruitHotsearchService.delete(hkUserRecruitHotsearch);
		addMessage(redirectAttributes, "删除职位热搜成功");
		return "redirect:"+Global.getAdminPath()+"/sys/job/hkUserRecruitHotsearch/?repage";
	}

}